package com.example.taluo.config;

import com.example.taluo.security.TokenFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*** @Author supersaiya
 * @Description TODO

 * @Date 2025/2/12 17:29

 * @Version 1.0*/
@Configuration
public class FilterConfig {
    @Autowired
    private TokenFilter tokenFilter;

    //配置过滤器
    @Bean
    public FilterRegistrationBean<TokenFilter> tokenFilterRegistration() {
        FilterRegistrationBean<TokenFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(tokenFilter);
        // 在FilterConfig.java中修改拦截规则
        registration.addUrlPatterns("/api/*","/socket.io/*");
        // 添加排除路径（重要！否则会拦截登录请求）
        registration.addInitParameter("exclusions", "/api/auth/login");
        registration.setOrder(1); // 设置过滤器的优先级，数值越小优先级越高
        return registration;
    }
}
